<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>权限管理</title>
    <jsp:include page="../../../../head.jsp"/>
    <%
        String parentid = request.getParameter("id");
        if (StringUtils.isEmpty(parentid)) {
            parentid = "";
        }
    %>
    <script type="text/javascript">
        var useState = $.mrdForm.ajaxdp("dropdown-useState");
        var hiddenState = $.mrdForm.ajaxdp("dropdown-hiddenState");
        var pmsType = $.mrdForm.ajaxdp("dropdown-pmsType");
        var parentId = "<%=parentid%>";
        var formSetting = {
            title: "查询模块权限",
            columns: [{
                name: "name",
                label: "权限名称"
            }, {
                name: "type",
                label: "权限类型",
                type: "dropdown",
                minLength: 0,
                data: pmsType
            }],
            buttons: {
                custom: [
                    {
                        id: "addPermissions",
                        value: "添加权限",
                        click: function () {
                            jw.dialog({
                                          iframe: 'mod-peradd?module.id=' + parentId,
                                          width: 500,
                                          height: 100,
                                          over: false
                                      });
                        }
                    },
                    {
                        id: "updatePermissions",
                        value: "修改权限",
                        click: function () {
                            var id = $("#sys_pms_list").jqGrid("getGridParam",
                                                               "selrow");
                            if (id) {
                                alert(module.id);
                                jw.dialog({
                                              iframe: 'mod-perupdate?module.id='
                                                      + parentId + '&permissions.id='
                                                      + id,
                                              width: 500,
                                              height: 100,
                                              over: false
                                          });
                            } else {
                                jw.alert("请选择需要修改的权限!");
                            }
                        }
                    },
                    {
                        id: "deletePermissions",
                        value: "删除权限",
                        click: function () {
                            var id = $("#sys_pms_list").jqGrid("getGridParam",
                                                               "selrow");
                            if (id) {
                                jw.confirm("确定删除选择的权限?", function () {
                                    $.ajax({
                                               "url": "mod-perdel",
                                               "data": {"permissions.id": id},
                                               "type": "post",
                                               "success": function (data) {
                                                   var msg = $.parseJSON(data.msg);
                                                   if (msg.state == "1") {
                                                       jw.alert(msg.msg);
                                                       $("#pmsForm").mrdForm(
                                                               "refreshGrid");
                                                   } else {
                                                       jw.alert(msg.msg);
                                                   }
                                               }
                                           });
                                });
                            } else {
                                jw.alert("请选择需要删除的权限!");
                            }
                        }
                    }]
            },
            grid: {
                id: "sys_pms_list",
                url: "mod-pdata",
                postData: {
                    "id": parentId
                },
                title: "权限列表",
                // 			sortname:"systemInterface.name",
                colModel: [{
                    index: "id",
                    name: "id",
                    hidden: true
                }, {
                    index: "name",
                    name: "name",
                    label: "权限名称"
                }, {
                    index: "pid",
                    name: "pid",
                    label: "权限标识"
                }, {
                    index: "type",
                    name: "type",
                    label: "权限类型",
                    dropdown: pmsType
                }, {
                    index: "disable",
                    name: "disable",
                    label: "启用状态",
                    dropdown: useState
                }, {
                    index: "label",
                    name: "label",
                    label: "按钮值"
                }, {
                    index: "buttonId",
                    name: "buttonId",
                    label: "按钮id"
                }, {
                    index: "click",
                    name: "click",
                    label: "触发事件"
                }, {
                    index: "hidden",
                    name: "hidden",
                    label: "隐藏状态",
                    dropdown: hiddenState
                }],
                jsonReader: {
                    root: "permissionses"
                }
            }
        };
        function refresh() {
            $("#pmsForm").mrdForm("refreshGrid");
        }
        $(document).ready(function () {
            $("#pmsForm").mrdForm(formSetting);
            $("#pmsForm").mrdForm("resize");
        });
    </script>
</head>
<body>
<div id="pmsForm"></div>
</body>
</html>
